/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sunspotworld.protocols;

import com.sun.spot.peripheral.radio.IProtocolManager;
import com.sun.spot.peripheral.radio.LowPanHeaderInfo;
import java.io.IOException;
import org.sunspotworld.PollMobileTask;
import org.sunspotworld.datawrappers.DataWrapper;
import org.sunspotworld.datawrappers.DataWrapperVector;
import org.sunspotworld.mydatawrappers.TrackingPacketFactory;

/**
 *
 * @author me
 */
public class DataTransferProtocol implements IProtocolManager {
    public static final byte PROTOCOL_NUM = MyProtocols.DATA_TRANSFER;
    
    public void processIncomingData(byte[] arg0, LowPanHeaderInfo arg1) {
        PollMobileTask.reportPoll();
        synchronized (DataWrapperVector.getInstance()) {
            int i=1;
            DataWrapper pkt;
            try {
                for (int j=0; j<arg0[0]; j++) {
                    pkt = TrackingPacketFactory.getInstance().constructDataWrapper(arg0, i);
                    DataWrapperVector.getInstance().add(pkt);
                    i += pkt.getSize();
                } 
                //MarketAgent.getInstance().updateValue(TimeKeeper.getInstance().currentTask(), i); 
                //MarketAgent.getInstance().updateDemand(TimeKeeper.getInstance().currentTask(), i);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }

}
